<template>
  <div class="comments">
    <van-nav-bar :title="`${comment.reply_count}条回复`" />
    <div class="scroll-wrap">
      <CommentItem :comment="comment"></CommentItem>
      <van-cell title="全部回复" />
      <CommentList
        :list="list"
        :art_id="comment.com_id"
        :type="'c'"
      ></CommentList>
    </div>
    <!-- 底部区域 -->
    <div class="reply-bottom">
      <van-button
        class="write-btn"
        @click="isPostShow = true"
        size="small"
        round
        >写评论</van-button
      >
    </div>
    <!-- /底部区域 -->
    <van-popup v-model="isPostShow" position="bottom" style="height: 30%">
      <!--
        v-if 条件渲染
          true：渲染元素节点
          false：不渲染
       -->
      <AddComment
        @post-success="onsuccess"
        :target="comment.com_id"
      ></AddComment>
    </van-popup>
  </div>
</template>

<script>
import CommentItem from '../CommentList/CommentItem'
import CommentList from '../CommentList'
import AddComment from '../AddComment'
export default {
  name: 'CommentReply',
  components: {
    CommentItem,
    CommentList,
    AddComment
  },
  data() {
    return {
      isPostShow: false,
      list: []
    }
  },
  // 给所有后代提供属性
  provide: function () {
    return {
      articleId: this.articleId
    }
  },
  props: {
    comment: {
      type: Object
    },
    articleId: {
      type: String,
      required: true
    }
  },
  created() {
    console.log(this.comment)
  },
  methods: {
    onsuccess(value) {
      this.isPostShow = false
      this.comment.reply_count++
      this.list.unshift(value.new_obj)
    }
  }
}
</script>

<style lang="less" scoped>
.comments {
  padding: 10px 0;
  .scroll-wrap {
    position: fixed;
    top: 92px;
    left: 0;
    right: 0;
    bottom: 88px;
    overflow-y: auto;
  }
  .reply-bottom {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 88px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #fff;
    border-top: 1px solid #d8d8d8;
    .write-btn {
      width: 60%;
    }
  }
}
</style>
